package com.easy.common.utils;

/**
 * 验证码工具类
 *
 * @author zhouRuoYu
 * @date 2022/11/16
 */
public class VerifyCodeUtils {

    private static final String[] patch = {"000000", "00000", "0000", "000", "00", "0", ""};

    /**
     * 获取6位验证码
     *
     * @param tele 参数
     * @return {@link String}
     */
    public static String getCode(String tele) {
        int hash = tele.hashCode();
        int encryption = 20206666;
        long result = hash ^ encryption;
        long nowTime = System.currentTimeMillis();
        result = result ^ nowTime;
        long code = result % 1000000;
        code = code < 0 ? -code : code;
        String codeStr = code + "";
        int len = codeStr.length();
        return patch[len] + codeStr;
    }

    public static void main(String[] args) {
        System.out.println(VerifyCodeUtils.getCode("333"));
    }

}
